<template>
  <el-container>
    <el-container>
      <!-- aside -->
      <el-aside width="200px">
        <el-row>
          <el-button round @click="addControl('div')">Div</el-button>
          <el-button round @click="addControl('button')">Button</el-button>
          <el-button type="primary" round @click="addControl('radio')"
            >Radio</el-button
          >
          <el-button type="success" round @click="addControl('checkbox')"
            >Checkbox</el-button
          >
          <el-button type="info" round @click="addControl('input')"
            >Input</el-button
          >
          <el-button type="warning" round @click="addControl('select')"
            >Select</el-button
          >
          <el-button type="danger" round @click="addControl('datepicker')"
            >DatePicker</el-button
          >
        </el-row>
      </el-aside>
      <el-container>
        <!-- main -->
        <el-main>
          <lowcode :data="data"></lowcode>
        </el-main>
        <el-footer>
          {{ data }}
        </el-footer>
      </el-container>
    </el-container>
    {{ current }}
  </el-container>
</template>

<script>
import lowcode, { libs } from "@/components/lowcode";

export default {
  components: {
    lowcode,
  },
  data() {
    return {
      current: null,
      data: [
        {
          tag: "div",
          type: "box",
          children: [
            {
              tag: "el-button",
              text: "初始按钮",
            },
          ],
        },
      ],
    };
  },
  methods: {
    addControl(ctype) {
      let control = libs[ctype];
      if (control) {
        this.data.push(control);
      }
    },
  },
  mounted() {
    this.$bus.on("current", (data) => {
      this.current = data;
    });
  },
};
</script>

<style>
.el-header,
.el-footer {
  background-color: #b3c0d1;
  color: #333;
  text-align: center;
  min-height: 60px;
}

.el-aside {
  background-color: #d3dce6;
  color: #333;
  text-align: center;
}

.el-main {
  background-color: #e9eef3;
  color: #333;
  text-align: center;
  min-height: 360px;
}

body > .el-container {
  margin-bottom: 40px;
}

.el-container:nth-child(5) .el-aside,
.el-container:nth-child(6) .el-aside {
  line-height: 260px;
}

.el-container:nth-child(7) .el-aside {
  line-height: 320px;
}
</style>